package com.zjs.jsp.ediorder.web;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.zjs.jsp.domain.bigdipper.BigDipperData;
import com.zjs.jsp.domain.config.WebHelpService;
import com.zjs.jsp.ediorder.service.bigdipper.BigDipperService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.MessageFormat;
import java.util.List;


/**
 * @author 李文
 * @create 2018-07-11 14:02
 **/
@RestController
public class DeliveryAreaController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(DeliveryAreaController.class);
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    @Autowired
    private BigDipperService bigDipperService;


    @ApiOperation(value = "查询配送范围是否可达 ", notes = "查询配送范围是否可达 ")
    @ApiImplicitParam(name = "root", value = "数据", required = true, dataType = "String", paramType = "body")
    @PostMapping("/order/query/area/{uuid}")
    public String orderInquiry(@PathVariable String uuid, @RequestBody List<BigDipperData> root, HttpServletRequest request) {
        LOGGER.info(uuid + " 接受的数据是 " + root + "  " + WebHelpService.getParameterMap(request));
        String y;
        try {
            y = bigDipperService.getHandleOrder(OBJECT_MAPPER.writeValueAsString(root), "1002", "8f2cca1f75e3c5b0");
        } catch (Exception e) {
            LOGGER.error("{}  调用北斗星服务异常 ", uuid, e);
            y = MessageFormat.format("{\"code\": {},\" description \":\"{}\",\"data\":[]}", "51000", "调用北斗星服务异常");
        }
        LOGGER.info(uuid + " 响应的数据是 {}", y);
        return y;
    }

}
